<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>

</head>
<body>
	<div class="fuck">
	<input type="file" onchange="checkExt(this)"/>
<script > 
var checkExt=function(file) {
    if(!(/(?:png)$/i.test(file.value))) {
        alert("只允许上传jpg和gif的图片");
        if(window.ActiveXObject) {//for IE
            file.select();//select the file ,and clear selection
            document.selection.clear();
        } else if(window.opera) {//for opera
            file.type="text";file.type="file";
        } else file.value="";//for FF,Chrome,Safari
    } else {
        alert("ok");//or you can do nothing here.
    }
};
</script>

	</div>
</body>
</html>